home *** CD-ROM | disk | FTP | other *** search
AmigaBASIC Source Code | 1978-04-08 | 6.0 KB | 258 lines |
- MAIN:
- GOSUB Instruct
- GOSUB InitGame
- GOSUB MakeBoard
- GOSUB MakeColorBoxes
- GOSUB MakeReadyBox
- GOSUB GetAnswer
- GOSUB StartGame
-
-
- StartGame:
- BREAK ON
- MENU ON
- Row=1
- ap=0 :fflag=0
- X=MOUSE(0)
- GOTO MouseHandler
- RETURN
-
- MakeBoard:
- SCREEN 2,320,200,4,1
- WINDOW 2," Master Mind ",(0,4)-(311,186),16,2
- PALETTE 0,1,0.933333,0.86667
- PALETTE 1,0.8,0.6666,0.6666
- PALETTE 2,0,0,0 'Black
- PALETTE 3,1,1,1 'White
- PALETTE 4,1,1,0
- PALETTE 5,0.133,0.133,1
- PALETTE 6,1,0.5333,0
- PALETTE 7,0.133,0.733,0.133
- PALETTE 8,1,0.0666,0.0666
- PALETTE 9,0.7333,0,1
- PALETTE 10,0.4,0.3333,0.3333
- PALETTE 11,0.7333,0.8,1
- PALETTE 14,0.1333,0.3333,0.8666
- Blank=10
- Top=10:Bottom=175
- Right=211:Left=100
- ClearBoard:
- LOCATE 3,29: COLOR 0,0
- PRINT " ";:COLOR 1,0
- LINE (Left,Top)-(Right,Bottom),1,bf
- LINE (Left-1,Top-1)-(Right+1,Bottom+1),2,b
- LINE (Left+78,Top+23)-(Right-6,Bottom-6),2,b
- FOR R=1 TO 8
- bb=Bottom-6-(17*R)
- LINE (Left+78,bb)-(Right-6,bb),2
- NEXT R
- LINE (Left+6,Top+14)-(Left+74,Top+24),Blank,bf
- LINE (Left+6,Top+14)-(Left+74,Top+24),14,b
- FOR R=1 TO 8
- FOR c=0 TO 3
- FillSpot R,c,Blank
- NEXT c
- NEXT R
- MakeBoardDone: RETURN
-
- MakeColorBoxes:
- ClrRgt=90:ClrLft=10:ClrBt=180
- LINE (ClrLft,0)-(ClrRgt,ClrBt),2,b
- FOR c=1 TO 6
- Tp=30*(c-1)
- LINE (ClrLft,Tp)-(ClrRgt,Tp+30),c+3,bf
- LINE (ClrLft,Tp)-(ClrRgt,Tp+30),2,b
- NEXT c
- MakeColorBoxesDone: RETURN
-
- MakeReadyBox:
- RLft=250:rrgt=300
- RTp=75:RBt=125
- LINE (RLft,RTp)-(rrgt,RBt),2,bf
- LINE (RLft+4,RTp+4)-(rrgt-4,RBt-4),11,bf
- LOCATE 13,33:COLOR 2,11
- PRINT "Ready"
- MakeReadyBoxDone:RETURN
-
- closeup:
- WINDOW CLOSE 2
- SCREEN CLOSE 2
- MENU RESET
- SYSTEM
- CloseUpDone:RETURN
-
- InitGame:
- DEFINT a-Z
- DIM Guess(3),Answer(3)
- ON BREAK GOSUB closeup
- MENU 1,0,1,"MasterMind"
- MENU 1,1,1," New Game "
- MENU 1,2,1," Peek "
- MENU 1,3,1," Give Up "
- MENU 1,4,1," Quit "
- ON MENU GOSUB MenuHandler
- InitGameDone: RETURN
-
- MenuHandler:
- Item=MENU(1)
- ON Item GOTO NewGame,APeek,ShowAnswer,closeup
-
- NewGame:
- Row=1
- ap=0 :fflag=0
- GOSUB GetAnswer
- GOSUB ClearBoard
- NewGameDone: RETURN MouseHandler
-
- APeek:
- IF ap>3 THEN ap=3
- FillSpot 9,ap,Answer(ap)
- ap=ap+1
- APeekDone: RETURN
-
- MouseHandler:
- WHILE MOUSE(0)=0
- WEND
- X=MOUSE(3):y=MOUSE(4)
- IF X<=ClrRgt THEN PickColor
- IF X<=Right-33 AND X>=Left+6 THEN MakeGuess
- IF X>=RLft AND y<=RBt AND y=>RTp THEN GuessReady
- MouseHandlerDone:GOTO MouseHandler
-
-
- PickColor:
- CurrClr=4+FIX(y/30)
- Newclr=1
- PickColorDone: GOTO MouseHandler
-
- MakeGuess:
- Colm=FIX((X-Left-6)/18)
- Guess(Colm)=CurrClr
- FillSpot Row,Colm,CurrClr
- MakeGuessDone: GOTO MouseHandler
-
- GetAnswer: RANDOMIZE TIMER
- FOR i=0 TO 3
- R: Answer(i)=4+FIX(6*RND)
- FOR j=i-1 TO 0 STEP -1
- IF Answer(i)=Answer(j) THEN R
- NEXT j
- NEXT i
- GetAnswerDone: RETURN
-
-
- MarkGuess:
- Place=0:Colr=0:j=0
- FOR i=0 TO 3
- WHILE j<4
- IF Answer(i)=Guess(i) THEN
- Place=Place+1
- GOTO iLoop
- ELSEIF Answer(i)=Guess(j) THEN
- Colr=Colr+1
- GOTO iLoop
- END IF
- j=j+1
- WEND
- iLoop:j=0:NEXT i
- FOR i=0 TO 3
- Guess(i)=Blank
- NEXT i
- MarkGuessDone:RETURN
-
- GuessReady:
- GOSUB MarkGuess
- IF Newclr=1 THEN Row=Row+1
- Newclr=0:R=Row-1
- ShowScore Place,Colr,R
- IF Place=4 OR Row>8 THEN Finished
- GuessReadyDone: GOTO MouseHandler
-
- Finished: fflag=1
- ShowScore pl,cl,Row
- LOCATE 3,29:COLOR 10,0
- BEEP
- IF Place<4 THEN PRINT " Sorry " :ELSE PRINT "You Win!"
- ShowAnswer: AnswRow=9
- FOR i=0 TO 3
- FillSpot AnswRow,i,Answer(i)
- NEXT i
- IF fflag THEN MouseHandler
- RETURN
-
- Instruct:
- WINDOW 2," MasterMind",,20
- CLS
- PRINT :PRINT
- PRINT " The game of Mastermind tests your powers of analytic deduction."
- PRINT " The object of this game is to determine the random combination"
- PRINT " of 4 different colors (out of 6) chosen by the computer. Make "
- PRINT " your guess by selecting a color from the column at the left with the"
- PRINT " mouse then clicking on a position on the lowest row of the game board to"
- PRINT " fill. Select a new color and continue to fill spots until your"
- PRINT " guess is finished. Be sure to check that the guess is a good "
- PRINT " one... no mistakes, duplicate colors or repeat guesses. Remember
- PRINT " you can change a guess by refilling it. When you are ready select"
- PRINT " READY. The computer will mark your guess by placing one black"
- PRINT " square in the box beside your guess for every color which is in"
- PRINT " the right spot and one white square for every color which occurs"
- PRINT " in the answer but is not in the right place. Thus the lowest possible"
- PRINT " score for a guess with 4 different colors in it is 2 whites
- PRINT " while the highest score (correct answer) is 4 blacks.
- PRINT " "
- PRINT " A good general strategy is to first determine the 4 colors"
- PRINT " while varying the positions in order to gain information for "
- PRINT " later use in determining the positions."
- PRINT " "
- t=MOUSE(0)
- PRINT " Click mouse to start!"
- WHILE NOT MOUSE(0)
- WEND
- WINDOW CLOSE 2
- InstructDone:RETURN
-
-
- SUB ShowScore(pl,cl,Rw) STATIC
- SHARED Bottom,Left
- MENU OFF
- t=Bottom-6-17*Rw
- l=Left+78
- spot=1:PPen=2:CPen=3
- FOR s=1 TO pl
- IF spot>2 THEN down=10 :ELSE down=2
- IF spot/2=FIX(spot/2) THEN over =16 :ELSE over =4
- IF spot<5 THEN LINE (l+over,t+down)-STEP (6,4),PPen,bf
- spot=spot+1
- NEXT s
- FOR s=1 TO cl
- IF spot>2 THEN down=10 :ELSE down=2
- IF spot/2=FIX(spot/2) THEN over =16 :ELSE over =4
- IF spot<5 THEN LINE (l+over,t+down)-STEP (6,4),CPen,bf
- spot=spot+1
- NEXT s
- MENU ON
- END SUB
-
- SUB FillSpot(Rw,cl,Clr) STATIC
- SHARED Bottom,Left
- MENU OFF
- cx=cl*16+14+Left
- Brdr=2
- cy=Bottom-10-((Rw-1)*17)
- ' CIRCLE (cx,cy),4,Brdr ' the cicrles looked better but were
- ' PAINT (cx,cy),Clr,Brdr ' quite slow, try it and see!
- LINE (cx+4,cy+4)-(cx-4,cy-4),Brdr,b
- LINE (cx+3,cy+3)-(cx-3,cy-3),Clr,bf
- MENU ON
- END SUB
-
-
-
-
-
-
-
-
-
-
-